/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/

/***********************************************************************
 *
 * FILENAME:
 * gtk_gpsmap.c
 *
 * PURPOSE:
 *	Provide a GPS map interface to the user.
 *
 * LAST MODIFIED:
 *
 ***********************************************************************/

#include "geoRefMap.h"
#include "utilities.h"

#include <iomanip>
using namespace std;

GeoRefMap::GeoRefMap(void)
{
	pixbuf = NULL;

	width = height = 0;
	dx_dPp = dy_dPp = 0.0;
	img_tieX = img_tieY = m_tieX = m_tieY = m_resX = m_resY = 0.0;
}

GeoRefMap::~GeoRefMap(void)
{
	Close();
}

void GeoRefMap::Close(void)
{
	if(pixbuf) gdk_pixbuf_unref(pixbuf); 
	pixbuf = NULL;

}

bool GeoRefMap::Open()
{
	return true;
}




bool GeoRefMap::geoToImage(double &x, double &y)
{
	x = (x - m_tieX) / m_resX + img_tieX;	
	y = (y - m_tieY) / m_resY + img_tieY;	

	return true;
}

void GeoRefMap::getTiePoints(double &x, double &y) 
{ 	
	x = m_tieX - img_tieX * m_resX; 
	y = m_tieY - img_tieY * m_resY; 

	return;
}

bool GeoRefMap::imageToGeo(double &x, double &y)
{
	x = (x - img_tieX) * m_resX + m_tieX;
	y = (y - img_tieY) * m_resY + m_tieY;

	return true;

}

char *DecToDDec( double dfAngle, const char * pszAxis, int nPrecision )
{
	char        szFormat[30];
	static char szBuffer[50];
	const char *pszHemisphere = NULL;

	if( EQUAL(pszAxis,"Long") && dfAngle < 0.0 )
		pszHemisphere = "W";
	else if( EQUAL(pszAxis,"Long") )
		pszHemisphere = "E";
	else if( dfAngle < 0.0 )
		pszHemisphere = "S";
	else
		pszHemisphere = "N";

	sprintf( szFormat, "%%%d.%df%s", nPrecision+5, nPrecision, pszHemisphere );
	sprintf( szBuffer, szFormat, dfAngle );

	return( szBuffer );
}


